from django.db import models
from django.contrib.auth.models import AbstractUser, UserManager as _UserManager


class UserManager(_UserManager):
    def create_superuser(self, username, password, email=None, **extra_fields):
        super().create_superuser(username=username, password=password, email=email, **extra_fields)



class User(AbstractUser):
    """
    自定义User模型，添加字段
    """
    mobile = models.CharField('手机号', max_length=11, unique=True, help_text='手机号', error_messages={'unique': '此手机号已被注册'})
    email_active = models.BooleanField('邮箱状态', default=False)

    class Meta:
        db_table = 'tb_user'  # 指定数据库表名
        verbose_name = '用户'  # 再admin站点中的显示名称
        verbose_name_plural = verbose_name  # 复数hu

    def __str__(self):
        return self.username

    # 通过creat_superuser创建用户必须要有的字段
    REQUIRED_FIELDS = ['mobile']

    objects = UserManager()